/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenDrug implements Generalisator{
    String[] chemotherapy = {"FEC", "TAXOTERE", "DOCETAXEL", "TAXOL", "HERCEPTIN", "NEOADJUVANT", "R-CHOP", "CARBOPLATIN", "TRASTUZAMAB", "VINORELBINE"};
    String[] hormones = {"ANASTRAZOLE", "ARIMIDEX", "TAMOXIFEN", "NOLVADEX", "AROMATASE", "ENDOCRINE", "EXEMESTANE", "FASLODEX", "FEMARA", "FLUCLOXACILLIN", "HERCEPTIN", "LETROZOLE", "FOSAMAX", "NORETHISTERONE", "ZOLADEX"};
    String[] other = {"LAPATINIB", "MEDX", "PAMIDRONATE", "TRASTUZUMAB", "ZOMETA"};
    @Override
    public String gen(String value){
        for(String target : chemotherapy){
            if(value.contains(target))
                return "CHEMOTHERAPY";
        }
        for(String target : hormones){
            if(value.contains(target))
                return "HORMONES";
        }
        for(String target : other){
            if(value.contains(target))
                return "OTHER";
        }
        return "*";     
    }

    @Override
    public int getMaxGeneralisation() {
        return 3;
    }

    @Override
    public double getLength(String value) {
        if(value.equals("*"))
            return 3.0;
        for(String target : chemotherapy){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : hormones){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : other){
            if(value.contains(target))
                return 1.0;
        }
        return 2.0;
    }

    @Override
    public double getMaxLength() {
        return 2.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        if(value.equals("*"))
            return "HORMONES";
        if(value.equals("HORMONES")){
            return hormones[rand.nextInt(hormones.length)];
        }
        if(value.equals("CHEMOTHERAPY")){
            return chemotherapy[rand.nextInt(chemotherapy.length)];
        }
        if(value.equals("OTHER")){
            return other[rand.nextInt(other.length)];
        }
        return "MEDX";
    }

    @Override
    public int getGeneralisationLevel(String value) {
        if(value.equals("*"))
            return 2;
        for(String target : chemotherapy){
            if(value.contains(target))
                return 0;
        }
        for(String target : hormones){
            if(value.contains(target))
                return 0;
        }
        for(String target : other){
            if(value.contains(target))
                return 0;
        }
        return 1;
    }
}
